

Function.prototype.myApply = function (context) {
  if (typeof this !== 'function') {
    throw TypeError('is not a function')
  }
  const ctx = context || window;
  const args = arguments[1] ? arguments[1] : [];
  ctx.fn = this;
  const res = ctx.fn(...args);
  delete ctx.fn;
  return res
}
Function.prototype.myCall = function (context) {
  if (typeof this !== 'function') {
    throw TypeError('is not a function')
  }
  const ctx = context || window;
  ctx.fn = this;
  const args = Array.from(arguments).slice(1);
  const res = ctx.fn(...args);
  delete ctx.fn;
  return res
}
Function.prototype.myBind = function (context) {
  if (typeof this !== 'function') {
    throw TypeError('is not a function')
  }
  const self = this;
  const args = Array.from(arguments).slice(1);
  const fn = function () {
    return self.apply(this instanceof fn ? this : context, args.concat(...arguments))
  }
  return fn

}